package com.kgo.eidtor.service.impl;

import cn.hutool.core.util.IdUtil;
import com.kgo.eidtor.dao.InterfaceBeanMapper;
import com.kgo.eidtor.dao.ProjectBeanMapper;
import com.kgo.eidtor.dao.StandardBeanMapper;
import com.kgo.eidtor.entity.InterfaceBean;
import com.kgo.eidtor.entity.ProjectBean;
import com.kgo.eidtor.entity.StandardBean;
import com.kgo.eidtor.entity.SysCodeBean;
import com.kgo.eidtor.service.InterfaceService;
import com.kgo.eidtor.service.ProjectService;
import com.kgo.eidtor.service.StandardService;
import com.kgo.eidtor.util.ResultUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ProjectServiceImpl implements ProjectService {
    @Resource
    private ProjectBeanMapper projectBeanMapper;
    @Resource
    private StandardBeanMapper standardBeanMapper;
    @Resource
    private InterfaceBeanMapper interfaceBeanMapper;
    @Override
    public int addProject(ProjectBean project) {
        if (StringUtils.isBlank(project.getId())){
            project.setId(IdUtil.simpleUUID());
        }
        return projectBeanMapper.insert(project);
    }

    @Override
    public String getProjectCodes() {
        List<SysCodeBean> projectCodes = projectBeanMapper.getProjectCode();
        int count = projectCodes.size();
        return ResultUtil.query(count,projectCodes);
    }

    @Override
    public String getProjectItemCount(String id) {
        Map<String,Object> project_item = new HashMap<>();
        //获取标准数量
        StandardBean standardBean = new StandardBean();
        standardBean.setProjectId(id);
        int standardCount = standardBeanMapper.getStandardCount(standardBean);
        project_item.put("standardCount",standardCount);
        //获取接口数量
        InterfaceBean interfaceBean = new InterfaceBean();
        interfaceBean.setProjectId(id);
        int interfaceCount = interfaceBeanMapper.getInterfaceCount(interfaceBean);
        project_item.put("interfaceCount",interfaceCount);

        return ResultUtil.query(1,project_item,"获取项目子项数量");
    }


}
